home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / +look_here_1st!+ / reader_requests / grabkick / grabkick.a < prev    next >
Text File  |  1997-11-28  |  7KB  |  239 lines

  1. * Programmheader
  2. *
  3. *    Name:        GrabKick
  4. *    Author:        SDI
  5. *    Distribution:    PD
  6. *    Description:    read Kickstart out of ROM and write it to file
  7. *    Compileropts:    -
  8. *    Linkeropts:    -
  9. *    CLI-Parameter:    FILENAME
  10. *
  11. * vers    date   length
  12. * 1.1   23.12.92  10612    : ANSI-C-Version made by Ralf Gruner
  13. *
  14. *    I used name and idea of this program, but not the ANSI-C code,
  15. *    because Amiga-ROM functions need no program space: 10612 --> 880 byte
  16. *    My program makes no output to user! It can fail at some positions,
  17. *    but these fails are so seldom that error messages aren't neccessary!
  18. *    The only needed error message (disk full) is made by system function.
  19. * 1.2   07.08.95    880    : new calculation for Revisionnummer works around
  20. *    calculation-error of MaxonC++
  21. * 1.3   03.12.95    244    : made new with Maxon Assembler
  22. * 1.4   04.12.95    236    : made shorter
  23. * 1.5   10.12.95    228    : made shorter
  24. * 1.6   19.12.95    300    : now also working from WorkBench
  25. * 1.7   05.01.96    332    : included CLI parameter FILENAME, removed some bugs
  26. * 1.8   10.02.96    508 : Asl-Requester on Workbench-start, new Icon
  27. * 1.9   11.02.96    488 : made shorter, commented text
  28. * 1.10  12.02.96    484 : made shorter
  29. * 1.11  14.02.96    476 : CMPA.L #0,Ax replaced by MOVE.L Ax,D0
  30. * 1.12  17.02.96    476 : BUG: Open_Mode is .L and not .W !
  31. * 1.13  08.03.96    472 : a little bit shorter, tricky LibName method,
  32. *    translated source to english
  33. * 1.14  11.04.96    472 : overworked the source code, no new binary file
  34. * 1.15  11.06.96    496 : removed a .L / .W error in name-creation, removed
  35. *    libname trick, added version-string to ASL-Req. title
  36. * 1.16  21.11.96    504 : added correct Return codes (#20 on failing)
  37. * 1.17  07.01.97    508 : added second exe copying the ROM first to RAM,
  38. *    corrected WB start Enforcer hit
  39.  
  40.     NOLIST
  41.     INCLUDE    AINCLUDE:IncDirs.i
  42.     INCLUDE    dos/dosextens.i
  43.     INCLUDE lvo.i
  44.     INCLUDE dos/dos.i
  45.     INCLUDE    exec/execbase.i
  46.     INCLUDE exec/memory.i
  47.     INCLUDE    workbench/startup.i
  48.     INCLUDE    workbench/workbench.i
  49.     INCLUDE    libraries/asl.i
  50.     LIST
  51.  
  52.     SECTION "GrabKick",CODE
  53.     MOVEA.L    A0,A5        ;store it
  54.     MOVE.L    D0,D6        ;store it
  55.     MOVEQ    #0,D5        ;no start string in D5
  56.     MOVEQ    #RETURN_FAIL,D7        ;return code - everytime fail
  57.     MOVE.L    D7,-(A7)
  58.     MOVEQ    #0,D7                ;D7 - clear (later StartupM)
  59.     MOVEA.L    4.W,A6
  60.     MOVEA.L    ThisTask(A6),A4
  61.     TST.L    pr_CLI(A4)        ;are we on WorkBench ?
  62.     BNE.B    .CLI
  63.     LEA    pr_MsgPort(A4),A0
  64.     JSR    _LVOWaitPort(A6)    ;wait for StartUp message
  65.     LEA    pr_MsgPort(A4),A0
  66.     JSR    _LVOGetMsg(A6)        ;get Message into D7
  67.     MOVE.L    D0,D7                ;D7 - WBStartUp message
  68.     BRA.B    .start
  69. .CLI    SUBQ.W    #1,D6
  70.     BEQ.B    .start        ;if only one char, no parameter is given
  71.     CLR.B    (A5,D6.W)        ;make C-string, last char is 0
  72.     MOVE.L    A5,D5                ;D5 - CLI parameter name
  73. .start    LEA    KICKEND(PC),A2            ;A2 - KickStr-End
  74.     MOVEQ    #33,D0
  75.     LEA    DOSNAME(PC),A1
  76.     JSR    _LVOOpenLibrary(A6)    ;open dos.library
  77.     TST.L    D0            ;fatal Error : librarybase = 0?
  78.     BEQ.B    .goend            ;instead of BEQ.W ENDE (-2 Byte)
  79.     MOVEA.L    D0,A5                ;A5 - DosBase
  80.     TST.L    D7
  81.     BEQ.B    .NoWB
  82.     MOVEA.L    D7,A0
  83.     MOVEA.L    sm_ArgList(A0),A0    ;on WB-start get PROGDIR:
  84.     MOVE.L    A0,D0            ;instead of CMPA.L #0,A0 (-4 Byte)
  85. .goend    BEQ.W    ENDE
  86.     MOVE.L    (A0),D1            ;set PROGDIR as current
  87.     MOVEA.L    A5,A6
  88.     JSR    _LVOCurrentDir(A6)
  89. .NoWB    LEA    $01000000,A3        ;Kick-ROM End is every time same!!!
  90.     MOVE.L    -20(A3),D3            ;D3 - RomSize
  91.     SUBA.L    D3,A3                ;A3 - Romstart
  92.     MOVEQ.L    #0,D4
  93.     MOVE.W    12(A3),D4            ;D4 - Romvers
  94.     MULU    #1000,D4
  95.     ADD.W    14(A3),D4            ;D4 - Fullversion
  96. .LOOP                    ;calculate kick..... name
  97.     MOVE.L    D4,D2
  98.     DIVU    #10,D2            ;divide with ten
  99.     MOVEQ    #0,D4
  100.     MOVE.W    D2,D4            ;store in D4
  101.     SWAP    D2
  102.     ADD.B    D2,-(A2)        ;remainder into namefile
  103.     TST.W    D4
  104.     BNE.B    .LOOP
  105. ;end of loop                    ;D4 - not used
  106.     MOVEA.L    D5,A2                ;A2 - CLI name or
  107.     TST.L    D5
  108.     BNE.B    .GoOn
  109.     LEA    KICKSTR(PC),A2            ;A2 - kick.....
  110. .GoOn    MOVEQ    #0,D6                ;D6 - clear (later AslBase)
  111.     MOVEQ    #0,D5                ;D5 - clear (later Lock)
  112.     TST.L    D7            ;if not WB then overgo asl-requester
  113.     BEQ.B    Open
  114.     MOVEA.L    4.W,A6
  115. **1111**
  116. *    LEA    DOSNAME(PC),A1        ;ugly trick : overwrite dos. with asl.
  117. *    MOVE.L    #'asl.',(A1)        ;saves some bytes!
  118.     LEA    ASLNAME(PC),A1
  119. **1111**
  120.     MOVEQ    #37,D0
  121.     JSR    _LVOOpenLibrary(A6)    ;open asl.library
  122.     MOVE.L    D0,D6                ;D6 - AslBase
  123.     BEQ.B    Open            ;failed ?, then like CLI
  124.     MOVEA.L    D6,A6
  125.     MOVEQ    #ASL_FileRequest,D0
  126.     LEA    TAGITEM(PC),A0
  127.     JSR    _LVOAllocAslRequest(A6)    ;create Request-struct
  128.     MOVEA.L    D0,A4                ;A4 - FileRequester
  129.     TST.L    D0
  130.     BEQ.B    Open            ;failed ?, then like CLI
  131.     MOVEA.L    A4,A0
  132.     LEA    TAGITEM(PC),A1
  133.     JSR    _LVOAslRequest(A6)    ;call requester
  134.     TST.L    D0
  135.     BEQ.B    CLEANUP            ;failed?, end!!!, it's user-abort
  136.     MOVE.L    fr_Drawer(A4),D1
  137.     MOVEQ    #SHARED_LOCK,D2        ;share the directory lock
  138.     MOVEA.L    A5,A6
  139.     JSR    _LVOLock(A6)        ;get lock on directory
  140.     MOVE.L    D0,D5                ;D5 - Lock
  141.     BEQ.B    CLEANUP            ;failed?, end!!!, else it makes shit
  142.     MOVE.L    D5,D1
  143.     JSR    _LVOCurrentDir(A6)    ;make selected directory current
  144.     MOVEA.L    fr_File(A4),A2            ;A2 - asl name
  145. Open
  146. **3333**
  147. *    MOVEA.L    4.W,A6
  148. *    MOVE.L    D3,D0            ;size of memory
  149. *    MOVEQ    #MEMF_PUBLIC,D1        ;memory type
  150. *    JSR    _LVOAllocMem(A6)    ;get memory
  151. *    MOVE.L    D0,D4
  152. *    BEQ.B    CLEANUP
  153. *    MOVEA.L    A3,A0            ;source buffer
  154. *    MOVEA.L    D4,A1            ;destination buffer
  155. *    MOVE.L    D3,D0            ;size
  156. *    JSR    _LVOCopyMemQuick(A6)    ;copy the memory
  157. *    MOVEA.L    D4,A3            ;new source is now RAM
  158. **3333**
  159.     MOVE.L    A2,D1            ;name parameter
  160.     MOVE.L    #MODE_NEWFILE,D2    ;mode parameter
  161.     MOVEA.L    A5,A6            ;set DosBase
  162.     JSR    _LVOOpen(A6)
  163.     MOVE.L    D0,D4                ;D4 - FileHandle
  164.     BEQ.B    CLEANUP2
  165.                 ;quantity parameter D3 has already it's value
  166.     MOVE.L    D4,D1            ;filehandle parameter
  167.     MOVE.L    A3,D2            ;buffer parameter
  168.     JSR    _LVOWrite(A6)
  169.     MOVE.L    D0,D2                ;D2 - returnstate of Write
  170.     MOVE.L    D4,D1            ;filehandle parameter
  171.     JSR    _LVOClose(A6)
  172.     CMP.L    D3,D2            ;D2 != D3, then delete File
  173.     BEQ.B    ALL_OK
  174.     MOVE.L    A2,D1
  175.     JSR    _LVODeleteFile(A6)
  176.     BRA.B    CLEANUP2
  177. ALL_OK    CLR.L    (A7)            ; all ok - clear return code
  178. CLEANUP2
  179. **3333**
  180. *    MOVEA.L    4.W,A6
  181. *    MOVEA.L    A3,A1        ;pointer to memory
  182. *    MOVE.L    D3,D0        ;size of memory
  183. *    JSR    _LVOFreeMem(A6)    ;free allocated memory
  184. *    MOVEA.L    A5,A6        ;reset DosBase for UnLock
  185. **3333**
  186. CLEANUP
  187.     MOVE.L    D5,D1
  188.     BEQ.B    .next            ;DosBase is already set, when D5 != 0
  189.     JSR    _LVOUnLock(A6)        ;free lock
  190. .next    TST.L    D6
  191.     BEQ.B    .clsdos
  192.     MOVE.L    A4,D0        ;instead oft CMPA.L #0,A4 (-4 Byte)
  193.     BEQ.B    .clsasl
  194.     MOVEA.L    A4,A0
  195.     MOVEA.L    D6,A6
  196.     JSR    _LVOFreeAslRequest(A6)    ;close filerequester
  197. .clsasl    MOVEA.L    4.W,A6
  198.     MOVEA.L    D6,A1
  199.     JSR    _LVOCloseLibrary(A6)    ;close asl.library
  200. .clsdos    MOVEA.L    4.W,A6
  201.     MOVEA.L    A5,A1
  202.     JSR    _LVOCloseLibrary(A6)    ;close dos.library
  203. ENDE
  204.     TST.L    D7            ;come we from Workbench ?
  205.     BEQ.B    .exit            ;no - was CLI
  206.  
  207.     JSR    _LVOForbid(A6)        ;make ReplyMsg save
  208.     MOVEA.L    D7,A1            ;get Message into A1
  209.     JSR    _LVOReplyMsg(A6)    ;end program
  210.  
  211. .exit    MOVE.L    (A7)+,D0
  212.     RTS    
  213. DOSNAME    DC.B    'dos.library',0
  214. **1111**
  215. ASLNAME    DC.B    'asl.library',0
  216. **1111**
  217. KICKSTR    DC.B    'kick00000'
  218. KICKEND    DC.B    0
  219. TAGITEM    DC.L    ASLFR_InitialFile,KICKSTR
  220. **2222**
  221.     DC.L    ASLFR_TitleText,VERSION
  222. **2222**
  223.     DC.L    0
  224.     DC.B    '$VER: '
  225. VERSION    DC.B    'GrabKick 1.17 (07.01.97) (PD) by SDI'
  226. **2222**
  227.     DC.B    0
  228. **2222**
  229.     ; 0 byte of the string is not needed, because in the file the header
  230.     ; does same as a 0 byte and in running state the string isn't used
  231.  
  232. * in the lines between **....** remove stars and set stars to the lines
  233. * without, for:
  234. * **1111** : remove the ugly asl.library name trick
  235. * **2222** : set ASL titletext to programname (needs 12 bytes more)
  236. * **3333** : set ROM->RAM->FILE copy mode
  237.     END
  238.  
  239.